package com.ruoyi.manage.cms.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.manage.cms.domain.HePtjs;
import com.ruoyi.manage.cms.domain.vo.HePtjsVo;
import com.ruoyi.manage.cms.service.IHePtjsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StrUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.poi.ExcelUtil;
/**
 * 平台介绍Controller
 *
 * @author ruoyi
 * @date 2025-07-23
 */
@Api(tags="平台介绍控制器")
@RestController
@RequestMapping("/manage/ptjs" )
public class HePtjsController extends BaseController {
    /**
    * 配置表别名 默认空
    */
    private final static String TABLE_PREFIX=StrUtil.initTableAlias(null);
    @Autowired
    private IHePtjsService hePtjsService;

    /**
     * 查询平台介绍列表
     */
    @ApiOperation(value = "查询平台介绍",notes = "平台介绍管理")
    @PreAuthorize("@ss.hasPermi('manage:ptjs:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(HePtjsVo hePtjs, QueryWrapper<HePtjs> queryWrapper) {
        setQueryCondition(hePtjs,queryWrapper);
        startPage();
        List<HePtjs> list = hePtjsService.list(queryWrapper);
        return getDataTable(list);
    }
    private void setQueryCondition(HePtjsVo hePtjs, QueryWrapper<HePtjs> queryWrapper) {
        queryWrapper.orderByDesc(TABLE_PREFIX+"create_time");
    }

    /**
     * 导出平台介绍列表
     */
    @PreAuthorize("@ss.hasPermi('manage:ptjs:export')" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, HePtjsVo hePtjs,QueryWrapper<HePtjs> queryWrapper) {
        if (CollUtil.isEmpty( hePtjs.getIds())){
            setQueryCondition(hePtjs,queryWrapper);
        }else {
            queryWrapper.in(TABLE_PREFIX+"id",hePtjs.getIds());
        }
        List<HePtjs> list = hePtjsService.list(queryWrapper);
        ExcelUtil<HePtjs> util = new ExcelUtil<HePtjs>(HePtjs. class);
        util.exportExcel(response,list, "ptjs");
    }

    /**
     * 获取平台介绍详细信息
     */
    @ApiOperation(value = "获取平台介绍",notes = "平台介绍管理")
    @PreAuthorize("@ss.hasPermi('manage:ptjs:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(hePtjsService.queryGetById(id));
    }

    /**
     * 新增平台介绍
     */
    @ApiOperation(value = "新增平台介绍",notes = "平台介绍管理")
    @PreAuthorize("@ss.hasPermi('manage:ptjs:add')" )
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@Validated @RequestBody HePtjs hePtjs) {
        return toAjax(hePtjsService.addHePtjs(hePtjs) ? 1 : 0);
    }

    /**
     * 修改平台介绍
     */
    @ApiOperation(value = "修改平台介绍",notes = "平台介绍管理")
    @PreAuthorize("@ss.hasPermi('manage:ptjs:edit')" )
    @PutMapping
    public AjaxResult edit(@RequestBody HePtjs hePtjs) {
        return toAjax(hePtjsService.updateHePtjs(hePtjs) ? 1 : 0);
    }

    /**
     * 删除平台介绍
     */
    @ApiOperation(value = "删除平台介绍",notes = "平台介绍管理")
    @PreAuthorize("@ss.hasPermi('manage:ptjs:remove')" )
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(hePtjsService.deleteHePtjsByIds(ids) ? 1 : 0);
    }
}
